<?php
class gopy
{
	var $idGopY;
	var $ChuDeGopY;
	var $NoiDungGopY;
	var $Email;
	var $TenKhachGopY;
	var $NgayGopY;
  
  
  function Convert($arr)
  {
	  $obj=new gopy();
	  $obj->idGopY=$arr['idGopY'];
	  $obj->ChuDeGopY=$arr['ChuDeGopY'];
	  $obj->NoiDungGopY=$arr['NoiDungGopY'];
	  $obj->Email=$arr['Email'];
	  $obj->TenKhachGopY=$arr['TenKhachGopY'];
	  $obj->NgayGopY=$arr['NgayGopY'];
	  return $obj;
  }
  
  
  //Hàm thêm góp ý
  static function ThemGopY($chude,$noidung,$email,$tenkhach,$ngay)
  {
	  $str=	"INSERT INTO GopY(ChuDeGopY,NoiDungGopY,Email,TenKhachGopY,NgayGopY)
	  			  VALUES('".$chude."','".$noidung."','".$email."','".$tenkhach."','".$ngay."')";				 
	  return Query($str);	
  }
  
  //Lấy tất cả góp ý
  static function GetAll($page = 1, $pagesize = 7)
  {
	  $start = ($page-1)*$pagesize;
	  $arr= array();
	  $str= "SELECT * FROM gopy limit $start,$pagesize" ;
	  $kq=Query($str);
	  $i=0;
	  while($row=mysql_fetch_array($kq))
	  {
		  $arr[$i]=self::ConVert($row);
		  $i++;	
	  }	
	  return $arr;
  }
  //Hàm đếm số lượng góp ý
	static function CountGopY()
	{
		$str = "select count(idGopY) from gopy";
		$kq = Query($str);
		$row = mysql_fetch_array($kq);
		return $row[0];
	}
  
  //Hàm xóa gopy
	static function Xoa($id)
	{
		$str="DELETE FROM gopy WHERE idGopY='".$id."'";	
		return Query($str);
	}
	
	//Hàm tìm kiếm góp ý theo chủ đề
  static function TimTheoChuDe($chude)
  {
	  $arr= array();
	  $str= "SELECT * FROM gopy WHERE  ChuDeGopY like '%$chude%'" ;
	  $kq=Query($str);
	  $i=0;
	  while($row=mysql_fetch_array($kq))
	  {
		  $arr[$i]=self::ConVert($row);
		  $i++;	
	  }	
	  return $arr;
  }
	
	//Hàm lấy góp ý theo id
  static function GetByID($id)
  {
	  $arr= array();
	  $str= "SELECT * FROM gopy WHERE  idGopY  = '".$id."'" ;
	  $kq=Query($str);
	  $i=0;
	  while($row=mysql_fetch_array($kq))
	  {
		  $arr[$i]=self::ConVert($row);
		  $i++;	
	  }	
	  return $arr;
  }
}
?>